﻿using System;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using IntelligentEscalator.BUS;
using IntelligentEscalator.Models;

namespace IntelligentEscalator.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    [Authorize]
    public class StatisticsController : ControllerBase
    {
        private readonly IHostingEnvironment _hostingEnvironment;
        private JwtSettings _jwtSettings;
        public StatisticsController(IHostingEnvironment hostingEnvironment, IOptions<JwtSettings> jwtSettingsAccesser)
        {
            _hostingEnvironment = hostingEnvironment;
            _jwtSettings = jwtSettingsAccesser.Value;
        }

        /// <summary>
        /// 故障分类
        /// </summary>
        /// <param name="faultRepairType">故障信息</param>
        /// <returns>success</returns>
        [HttpPost]
        [Route("FaultTypeSum")]
        public ResponseMessage FaultTypeSum(FaultRepairType faultRepairType)
        {
            ResponseMessage message = new ResponseMessage();
            StatisticsBUS BUS = new StatisticsBUS();
            try
            {
                message = BUS.GetFaultType(faultRepairType.faultType, faultRepairType.endtime);
            }
            catch (Exception e)
            {
                message.errcode = 1;
                message.errmsg = "查询故障分类失败";
                message.data = null;
                message.total = 0;
                LogHelper.Log(e.ToString());
                LogBUS logBUS = new LogBUS();
                ErrorLogInfo errorLogInfo = new ErrorLogInfo();
                errorLogInfo.operation = "查询故障分类";
                errorLogInfo.errorMsg = e.ToString();
                logBUS.InsertErrorLog(errorLogInfo);
            }
            return message;
        }

        /// <summary>
        /// 故障分类列表
        /// </summary>
        /// <param name="faultRepairType">故障信息</param>
        /// <returns>success</returns>
        [HttpPost]
        [Route("FaultTypeSumList")]
        public ResponseMessage FaultTypeSumList(FaultRepairType faultRepairType)
        {
            ResponseMessage message = new ResponseMessage();
            StatisticsBUS BUS = new StatisticsBUS();
            try
            {
                message = BUS.GetFaultTypeList(faultRepairType.faultTypeArray, faultRepairType.starttime, faultRepairType.endtime, faultRepairType.Recordhead, faultRepairType.Recordtail);
            }
            catch (Exception e)
            {
                message.errcode = 1;
                message.errmsg = "查询故障分类列表失败";
                message.data = null;
                message.total = 0;
                LogHelper.Log(e.ToString());
                LogBUS logBUS = new LogBUS();
                ErrorLogInfo errorLogInfo = new ErrorLogInfo();
                errorLogInfo.operation = "查询故障分类列表";
                errorLogInfo.errorMsg = e.ToString();
                logBUS.InsertErrorLog(errorLogInfo);
            }
            return message;
        }

        /// <summary>
        /// 导出故障分类
        /// </summary>
        /// <param name="faultRepairType">故障信息</param>
        /// <returns>success</returns>
        [HttpPost]
        [Route("ExportFaultTypeSum")]
        public ResponseMessage ExportFaultTypeSum(FaultRepairType faultRepairType)
        {
            ResponseMessage message = new ResponseMessage();
            try
            {
                StatisticsBUS BUS = new StatisticsBUS();

                string sWebRootFolder = _hostingEnvironment.WebRootPath;
                message = BUS.ExportFaultType(faultRepairType.faultTypeArray, faultRepairType.starttime, faultRepairType.endtime, sWebRootFolder);

                if (message.errcode == 0)
                {
                    string username = HttpContext.Session.GetString("UserName").ToString();
                    LogBUS logBUS = new LogBUS();
                    OperationLog operationLog = new OperationLog();
                    operationLog.operation = "导出故障分类统计";
                    operationLog.operatorName = username;
                    logBUS.InsertOperationLog(operationLog);
                }
            }
            catch (Exception e)
            {
                message.errcode = 1;
                message.errmsg = "导出故障分类失败";
                message.data = null;
                message.total = 0;
                LogHelper.Log(e.ToString());
                LogBUS logBUS = new LogBUS();
                ErrorLogInfo errorLogInfo = new ErrorLogInfo();
                errorLogInfo.operation = "导出故障分类";
                errorLogInfo.errorMsg = e.ToString();
                logBUS.InsertErrorLog(errorLogInfo);
            }
            return message;
        }

        /// <summary>
        /// 故障次数
        /// </summary>
        /// <param name="elevator">电梯信息</param>
        /// <returns>success</returns>
        [HttpPost]
        [Route("ElevatorFaultSum")]
        public ResponseMessage ElevatorFaultSum(Elevator elevator)
        {
            ResponseMessage message = new ResponseMessage();
            StatisticsBUS BUS = new StatisticsBUS();
            try
            {
                message = BUS.GetElevatorFault(elevator.id, elevator.endtime);
            }
            catch (Exception e)
            {
                message.errcode = 1;
                message.errmsg = "查询电梯故障次数失败";
                message.data = null;
                message.total = 0;
                LogHelper.Log(e.ToString());
                LogBUS logBUS = new LogBUS();
                ErrorLogInfo errorLogInfo = new ErrorLogInfo();
                errorLogInfo.operation = "查询电梯故障次数";
                errorLogInfo.errorMsg = e.ToString();
                logBUS.InsertErrorLog(errorLogInfo);
            }
            return message;
        }

        /// <summary>
        /// 故障次数列表
        /// </summary>
        /// <param name="elevator">电梯信息</param>
        /// <returns>success</returns>
        [HttpPost]
        [Route("ElevatorFaultSumList")]
        public ResponseMessage ElevatorFaultSumList(Elevator elevator)
        {
            ResponseMessage message = new ResponseMessage();
            StatisticsBUS BUS = new StatisticsBUS();
            try
            {
                message = BUS.GetElevatorFaultList(elevator.elevatorIds, elevator.starttime, elevator.endtime, elevator.Recordhead, elevator.Recordtail);
            }
            catch (Exception e)
            {
                message.errcode = 1;
                message.errmsg = "查询电梯故障次数列表失败";
                message.data = null;
                message.total = 0;
                LogHelper.Log(e.ToString());
                LogBUS logBUS = new LogBUS();
                ErrorLogInfo errorLogInfo = new ErrorLogInfo();
                errorLogInfo.operation = "查询电梯故障次数列表";
                errorLogInfo.errorMsg = e.ToString();
                logBUS.InsertErrorLog(errorLogInfo);
            }
            return message;
        }

        /// <summary>
        /// 导出故障次数
        /// </summary>
        /// <param name="elevator">故障信息</param>
        /// <returns>success</returns>
        [HttpPost]
        [Route("ExportElevatorFault")]
        public ResponseMessage ExportElevatorFault(Elevator elevator)
        {
            ResponseMessage message = new ResponseMessage();
            try
            {
                StatisticsBUS BUS = new StatisticsBUS();
                string sWebRootFolder = _hostingEnvironment.WebRootPath;
                message = BUS.ExportElevatorFaultSum(elevator.elevatorIds, elevator.starttime, elevator.endtime, sWebRootFolder);
                if (message.errcode == 0)
                {
                    string username = HttpContext.Session.GetString("UserName").ToString();
                    LogBUS logBUS = new LogBUS();
                    OperationLog operationLog = new OperationLog();
                    operationLog.operation = "导出故障次数统计";
                    operationLog.operatorName = username;
                    logBUS.InsertOperationLog(operationLog);
                }
            }
            catch (Exception e)
            {
                message.errcode = 1;
                message.errmsg = "导出故障次数失败";
                message.data = null;
                message.total = 0;
                LogHelper.Log(e.ToString());
                LogBUS logBUS = new LogBUS();
                ErrorLogInfo errorLogInfo = new ErrorLogInfo();
                errorLogInfo.operation = "导出故障次数";
                errorLogInfo.errorMsg = e.ToString();
                logBUS.InsertErrorLog(errorLogInfo);
            }
            return message;
        }

        /// <summary>
        /// 运行次数统计
        /// </summary>
        /// <param name="statisticsinfo">时间</param>
        /// <returns>success</returns>
        [HttpPost]
        [Route("GetElevatorRuns")]
        public ResponseMessage GetElevatorRuns(Elevator elevator)
        {
            ResponseMessage message = new ResponseMessage();
            StatisticsBUS BUS = new StatisticsBUS();
            try
            {
                message = BUS.GetElevatorRuns(elevator.id, elevator.endtime);
            }
            catch (Exception e)
            {
                message.errcode = 1;
                message.errmsg = "查询运行次数失败";
                message.data = null;
                message.total = 0;
                LogHelper.Log(e.ToString());
                LogBUS logBUS = new LogBUS();
                ErrorLogInfo errorLogInfo = new ErrorLogInfo();
                errorLogInfo.operation = "查询运行次数";
                errorLogInfo.errorMsg = e.ToString();
                logBUS.InsertErrorLog(errorLogInfo);
            }
            return message;
        }

        /// <summary>
        /// 运行次数列表
        /// </summary>
        /// <param name="statisticsinfo">时间</param>
        /// <returns>success</returns>
        [HttpPost]
        [Route("GetElevatorRunsList")]
        public ResponseMessage GetElevatorRunsList(Elevator elevator)
        {
            ResponseMessage message = new ResponseMessage();
            StatisticsBUS BUS = new StatisticsBUS();
            try
            {
                message = BUS.GetElevatorRunsList(elevator.elevatorIds, elevator.starttime, elevator.endtime, elevator.Recordhead, elevator.Recordtail);
            }
            catch (Exception e)
            {
                message.errcode = 1;
                message.errmsg = "查询运行次数列表失败";
                message.data = null;
                message.total = 0;
                LogHelper.Log(e.ToString());
                LogBUS logBUS = new LogBUS();
                ErrorLogInfo errorLogInfo = new ErrorLogInfo();
                errorLogInfo.operation = "查询运行次数列表";
                errorLogInfo.errorMsg = e.ToString();
                logBUS.InsertErrorLog(errorLogInfo);
            }
            return message;
        }

        /// <summary>
        /// 导出运行次数
        /// </summary>
        /// <param name="elevator">电梯信息</param>
        /// <returns>success</returns>
        [HttpPost]
        [Route("ExportElevatorRuns")]
        public ResponseMessage ExportElevatorRuns(Elevator elevator)
        {
            ResponseMessage message = new ResponseMessage();
            try
            {
                StatisticsBUS BUS = new StatisticsBUS();
                string sWebRootFolder = _hostingEnvironment.WebRootPath;
                message = BUS.ExportElevatorRuns(elevator.elevatorIds, elevator.starttime, elevator.endtime, sWebRootFolder);
                if (message.errcode == 0)
                {
                    string username = HttpContext.Session.GetString("UserName").ToString();
                    LogBUS logBUS = new LogBUS();
                    OperationLog operationLog = new OperationLog();
                    operationLog.operation = "导出运行次数统计";
                    operationLog.operatorName = username;
                    logBUS.InsertOperationLog(operationLog);
                }
            }
            catch (Exception e)
            {
                message.errcode = 1;
                message.errmsg = "导出运行次数失败";
                message.data = null;
                message.total = 0;
                LogHelper.Log(e.ToString());
                LogBUS logBUS = new LogBUS();
                ErrorLogInfo errorLogInfo = new ErrorLogInfo();
                errorLogInfo.operation = "导出运行次数";
                errorLogInfo.errorMsg = e.ToString();
                logBUS.InsertErrorLog(errorLogInfo);
            }
            return message;
        }

        /// <summary>
        /// 维修次数
        /// </summary>
        /// <param name="statisticsinfo">时间</param>
        /// <returns>success</returns>
        [HttpPost]
        [Route("GetRepairCount")]
        public ResponseMessage GetRepairCount(Statistics statisticsinfo)
        {
            ResponseMessage message = new ResponseMessage();
            StatisticsBUS BUS = new StatisticsBUS();
            try
            {
                message = BUS.GetRepairCount(statisticsinfo.startTime, statisticsinfo.endTime, statisticsinfo.elevatorids);
            }
            catch (Exception e)
            {
                message.errcode = 1;
                message.errmsg = "查询走修次数失败";
                message.data = null;
                message.total = 0;
                LogHelper.Log(e.ToString());
                LogBUS logBUS = new LogBUS();
                ErrorLogInfo errorLogInfo = new ErrorLogInfo();
                errorLogInfo.operation = "查询走修次数";
                errorLogInfo.errorMsg = e.ToString();
                logBUS.InsertErrorLog(errorLogInfo);
            }
            return message;
        }

        /// <summary>
        /// 维修次数列表
        /// </summary>
        /// <param name="statisticsinfo">时间</param>
        /// <returns>success</returns>
        [HttpPost]
        [Route("GetRepairCountList")]
        public ResponseMessage GetRepairCountList(Statistics statisticsinfo)
        {
            ResponseMessage message = new ResponseMessage();
            StatisticsBUS BUS = new StatisticsBUS();
            try
            {
                message = BUS.GetRepairCountList(statisticsinfo.startTime, statisticsinfo.endTime, statisticsinfo.order, statisticsinfo.Recordhead, statisticsinfo.Recordtail, statisticsinfo.elevatorids);
            }
            catch (Exception e)
            {
                message.errcode = 1;
                message.errmsg = "查询走修次数排名失败";
                message.data = null;
                message.total = 0;
                LogHelper.Log(e.ToString());
                LogBUS logBUS = new LogBUS();
                ErrorLogInfo errorLogInfo = new ErrorLogInfo();
                errorLogInfo.operation = "查询走修次数排名";
                errorLogInfo.errorMsg = e.ToString();
                logBUS.InsertErrorLog(errorLogInfo);
            }
            return message;
        }

        /// <summary>
        /// 导出维修次数
        /// </summary>
        /// <param name="elevator">电梯信息</param>
        /// <returns>success</returns>
        [HttpPost]
        [Route("ExportRepairCount")]
        public ResponseMessage ExportRepairCount(Statistics statisticsinfo)
        {
            ResponseMessage message = new ResponseMessage();
            try
            {
                StatisticsBUS BUS = new StatisticsBUS();
                string sWebRootFolder = _hostingEnvironment.WebRootPath;
                message = BUS.ExportRepairCount(statisticsinfo.startTime, statisticsinfo.endTime, statisticsinfo.order, sWebRootFolder, statisticsinfo.elevatorids);
                if (message.errcode == 0)
                {
                    string username = HttpContext.Session.GetString("UserName").ToString();
                    LogBUS logBUS = new LogBUS();
                    OperationLog operationLog = new OperationLog();
                    operationLog.operation = "导出维修次数统计";
                    operationLog.operatorName = username;
                    logBUS.InsertOperationLog(operationLog);
                }
            }
            catch (Exception e)
            {
                message.errcode = 1;
                message.errmsg = "导出维修次数失败";
                message.data = null;
                message.total = 0;
                LogHelper.Log(e.ToString());
                LogBUS logBUS = new LogBUS();
                ErrorLogInfo errorLogInfo = new ErrorLogInfo();
                errorLogInfo.operation = "导出维修次数";
                errorLogInfo.errorMsg = e.ToString();
                logBUS.InsertErrorLog(errorLogInfo);
            }
            return message;
        }


        /// <summary>
        /// 运行时间统计
        /// </summary>
        /// <param name="elevator">电梯信息</param>
        /// <returns>success</returns>
        [HttpPost]
        [Route("GetElevatorRunsTime")]
        public ResponseMessage GetElevatorRunsTime(Elevator elevator)
        {
            ResponseMessage message = new ResponseMessage();
            StatisticsBUS BUS = new StatisticsBUS();
            try
            {
                message = BUS.GetElevatorRunTime(elevator.id, elevator.endtime);
            }
            catch (Exception e)
            {
                message.errcode = 1;
                message.errmsg = "查询运行时间失败";
                message.data = null;
                message.total = 0;
                LogHelper.Log(e.ToString());
                LogBUS logBUS = new LogBUS();
                ErrorLogInfo errorLogInfo = new ErrorLogInfo();
                errorLogInfo.operation = "查询运行时间";
                errorLogInfo.errorMsg = e.ToString();
                logBUS.InsertErrorLog(errorLogInfo);
            }
            return message;
        }

        /// <summary>
        /// 运行时间列表
        /// </summary>
        /// <param name="elevator">电梯信息</param>
        /// <returns>success</returns>
        [HttpPost]
        [Route("GetElevatorRunsTimeList")]
        public ResponseMessage GetElevatorRunsTimeList(Elevator elevator)
        {
            ResponseMessage message = new ResponseMessage();
            StatisticsBUS BUS = new StatisticsBUS();
            try
            {
                message = BUS.GetElevatorRunTimeList(elevator.elevatorIds, elevator.starttime, elevator.endtime, elevator.Recordhead, elevator.Recordtail);
            }
            catch (Exception e)
            {
                message.errcode = 1;
                message.errmsg = "查询运行时间列表失败";
                message.data = null;
                message.total = 0;
                LogHelper.Log(e.ToString());
                LogBUS logBUS = new LogBUS();
                ErrorLogInfo errorLogInfo = new ErrorLogInfo();
                errorLogInfo.operation = "查询运行时间列表";
                errorLogInfo.errorMsg = e.ToString();
                logBUS.InsertErrorLog(errorLogInfo);
            }
            return message;
        }

        /// <summary>
        /// 导出运行时间
        /// </summary>
        /// <param name="elevator">电梯信息</param>
        /// <returns>success</returns>
        [HttpPost]
        [Route("ExportElevatorRunsTime")]
        public ResponseMessage ExportElevatorRunsTime(Elevator elevator)
        {
            ResponseMessage message = new ResponseMessage();
            try
            {
                StatisticsBUS BUS = new StatisticsBUS();
                string sWebRootFolder = _hostingEnvironment.WebRootPath;
                message = BUS.ExportElevatorRunsTime(elevator.elevatorIds, elevator.starttime, elevator.endtime, sWebRootFolder);
                if (message.errcode == 0)
                {
                    string username = HttpContext.Session.GetString("UserName").ToString();
                    LogBUS logBUS = new LogBUS();
                    OperationLog operationLog = new OperationLog();
                    operationLog.operation = "导出运行时间统计";
                    operationLog.operatorName = username;
                    logBUS.InsertOperationLog(operationLog);
                }
            }
            catch (Exception e)
            {
                message.errcode = 1;
                message.errmsg = "导出运行时间失败";
                message.data = null;
                message.total = 0;
                LogHelper.Log(e.ToString());
                LogBUS logBUS = new LogBUS();
                ErrorLogInfo errorLogInfo = new ErrorLogInfo();
                errorLogInfo.operation = "导出运行时间";
                errorLogInfo.errorMsg = e.ToString();
                logBUS.InsertErrorLog(errorLogInfo);
            }
            return message;
        }

        /// <summary>
        /// 故障排名
        /// </summary>
        /// <param name="elevatorFaultRank">信息</param>
        /// <returns>success</returns>
        [HttpPost]
        [Route("ElevatorFaultRank")]
        public ResponseMessage ElevatorFaultRank(ElevatorFaultRank elevatorFaultRank)
        {
            ResponseMessage message = new ResponseMessage();
            StatisticsBUS BUS = new StatisticsBUS();
            try
            {
                message = BUS.GetFaultCount(elevatorFaultRank.startTime, elevatorFaultRank.endTime, elevatorFaultRank.order);
            }
            catch (Exception e)
            {
                message.errcode = 1;
                message.errmsg = "查询故障排名失败";
                message.data = null;
                message.total = 0;
                LogHelper.Log(e.ToString());
                LogBUS logBUS = new LogBUS();
                ErrorLogInfo errorLogInfo = new ErrorLogInfo();
                errorLogInfo.operation = "查询故障排名";
                errorLogInfo.errorMsg = e.ToString();
                logBUS.InsertErrorLog(errorLogInfo);
            }
            return message;
        }

        /// <summary>
        /// 故障排名列表
        /// </summary>
        /// <param name="elevatorFaultRank">信息</param>
        /// <returns>success</returns>
        [HttpPost]
        [Route("ElevatorFaultRankList")]
        public ResponseMessage ElevatorFaultRankList(ElevatorFaultRank elevatorFaultRank)
        {
            ResponseMessage message = new ResponseMessage();
            StatisticsBUS BUS = new StatisticsBUS();
            try
            {
                message = BUS.GetFaultCountList(elevatorFaultRank.elevatorids, elevatorFaultRank.startTime, elevatorFaultRank.endTime, elevatorFaultRank.order, elevatorFaultRank.Recordhead, elevatorFaultRank.Recordtail);
            }
            catch (Exception e)
            {
                message.errcode = 1;
                message.errmsg = "查询故障排名列表失败";
                message.data = null;
                message.total = 0;
                LogHelper.Log(e.ToString());
                LogBUS logBUS = new LogBUS();
                ErrorLogInfo errorLogInfo = new ErrorLogInfo();
                errorLogInfo.operation = "查询故障排名列表";
                errorLogInfo.errorMsg = e.ToString();
                logBUS.InsertErrorLog(errorLogInfo);
            }
            return message;
        }

        /// <summary>
        /// 导出故障排名
        /// </summary>
        /// <param name="elevator">电梯信息</param>
        /// <returns>success</returns>
        [HttpPost]
        [Route("ExportElevatorFaultRank")]
        public ResponseMessage ExportElevatorFaultRank(ElevatorFaultRank elevatorFaultRank)
        {
            ResponseMessage message = new ResponseMessage();
            try
            {
                StatisticsBUS BUS = new StatisticsBUS();
                string sWebRootFolder = _hostingEnvironment.WebRootPath;
                message = BUS.ExportElevatorFaultRank(elevatorFaultRank.startTime, elevatorFaultRank.endTime, elevatorFaultRank.order, sWebRootFolder, elevatorFaultRank.elevatorids);
                if (message.errcode == 0)
                {
                    string username = HttpContext.Session.GetString("UserName").ToString();
                    LogBUS logBUS = new LogBUS();
                    OperationLog operationLog = new OperationLog();
                    operationLog.operation = "导出故障排名统计";
                    operationLog.operatorName = username;
                    logBUS.InsertOperationLog(operationLog);
                }
            }
            catch (Exception e)
            {
                message.errcode = 1;
                message.errmsg = "导出故障排名失败";
                message.data = null;
                message.total = 0;
                LogHelper.Log(e.ToString());
                LogBUS logBUS = new LogBUS();
                ErrorLogInfo errorLogInfo = new ErrorLogInfo();
                errorLogInfo.operation = "导出故障排名";
                errorLogInfo.errorMsg = e.ToString();
                logBUS.InsertErrorLog(errorLogInfo);
            }
            return message;
        }

        /// <summary>
        /// 查询所有故障类别
        /// </summary>
        /// <returns>success</returns>
        [HttpPost]
        [Route("QueryAllFaultType")]
        public ResponseMessage QueryAllFaultType()
        {
            ResponseMessage message = new ResponseMessage();
            try
            {
                FaultRepairBUS BUS = new FaultRepairBUS();
                message = BUS.QueryAllFaultType();
            }
            catch (Exception e)
            {
                message.errcode = 3;
                message.errmsg = "查询所有故障类别失败";
                message.data = null;
                message.total = 0;
                LogHelper.Log(e.ToString());
                LogBUS logBUS = new LogBUS();
                ErrorLogInfo errorLogInfo = new ErrorLogInfo();
                errorLogInfo.operation = "查询所有故障类别";
                errorLogInfo.errorMsg = e.ToString();
                logBUS.InsertErrorLog(errorLogInfo);
            }
            return message;
        }

        /// <summary>
        /// 查询故障列表
        /// </summary>
        /// <param name="elevator">设备信息</param>
        /// 
        /// <returns>success</returns>
        [HttpPost]
        [Route("QueryFaultListByElevator")]
        public ResponseMessage QueryFaultListByElevator(Elevator elevator)
        {
            ResponseMessage message = new ResponseMessage();
            RepairWorkOrderBUS BUS = new RepairWorkOrderBUS();
            try
            {
                message = BUS.QueryFaultByElevatorIds(elevator);
            }
            catch (Exception e)
            {
                message.errcode = 3;
                message.errmsg = "查询故障列表失败";
                message.data = null;
                message.total = 0;
                LogHelper.Log(e.ToString());
                LogBUS logBUS = new LogBUS();
                ErrorLogInfo errorLogInfo = new ErrorLogInfo();
                errorLogInfo.operation = "查询故障列表";
                errorLogInfo.errorMsg = e.ToString();
                logBUS.InsertErrorLog(errorLogInfo);
            }
            return message;
        }

        /// <summary>
        /// 导出故障列表
        /// </summary>
        /// <param name="elevator">电梯信息</param>
        /// <returns>success</returns>
        [HttpPost]
        [Route("ExportFaultListByElevator")]
        public ResponseMessage ExportFaultListByElevator(Elevator elevator)
        {
            ResponseMessage message = new ResponseMessage();
            try
            {
                StatisticsBUS BUS = new StatisticsBUS();
                string sWebRootFolder = _hostingEnvironment.WebRootPath;
                message = BUS.ExportFaultListByElevator(elevator.starttime, elevator.endtime,"", sWebRootFolder, elevator.elevatorIds);
                if (message.errcode == 0)
                {
                    string username = HttpContext.Session.GetString("UserName").ToString();
                    LogBUS logBUS = new LogBUS();
                    OperationLog operationLog = new OperationLog();
                    operationLog.operation = "导出故障列表统计";
                    operationLog.operatorName = username;
                    logBUS.InsertOperationLog(operationLog);
                }
            }
            catch (Exception e)
            {
                message.errcode = 1;
                message.errmsg = "导出故障排名失败";
                message.data = null;
                message.total = 0;
                LogHelper.Log(e.ToString());
                LogBUS logBUS = new LogBUS();
                ErrorLogInfo errorLogInfo = new ErrorLogInfo();
                errorLogInfo.operation = "导出故障排名";
                errorLogInfo.errorMsg = e.ToString();
                logBUS.InsertErrorLog(errorLogInfo);
            }
            return message;
        }
    }
}
